package com.example.administrator.compileapp;

import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.administrator.compileapp.drawer.FunctionIntrodutionActivity;
import com.example.administrator.compileapp.drawer.LoginActivity;
import com.example.administrator.compileapp.drawer.PersonalInformationyActivity;
import com.example.administrator.compileapp.databinding.FragmentDrawerBinding;
import com.example.administrator.compileapp.drawer.FeedBackActivity;
import com.example.administrator.compileapp.until.CircleTransformation;
import com.squareup.picasso.Picasso;


/**
 * A simple {@link Fragment} subclass.
 */
public class DrawerFragment extends Fragment implements View.OnClickListener {
    private FragmentDrawerBinding binding;
   private int color = -1;

    public static DrawerFragment newInstance(String nickName,String figureurl_qq_1) {
        Bundle args = new Bundle();
        args.putString("nickName",nickName);
        args.putString("figureurl_qq_1",figureurl_qq_1);
        DrawerFragment fragment = new DrawerFragment();
        fragment.setArguments(args);
        return fragment;
    }
    public DrawerFragment() {
        // Required empty public constructor
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        return DataBindingUtil.inflate(inflater, R.layout.fragment_drawer, container, false).getRoot();
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        binding = DataBindingUtil.getBinding(view);
        binding.drawerNickName.setText(getArguments().getString("nickName"));
        Picasso.with(getContext()).
                load(getArguments().getString("figureurl_qq_1")).transform(new CircleTransformation())
                .placeholder(R.mipmap.ogm).
                into(binding.drawerNickImage);
        binding.drawerItem1.setOnClickListener(this);
        binding.drawerItem2.setOnClickListener(this);
        binding.drawerItem3.setOnClickListener(this);
        binding.drawerItem4.setOnClickListener(this);
        binding.drawerItem5.setOnClickListener(this);
        binding.drawerItem6.setOnClickListener(this);
        binding.drawerItem7.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.drawer_item1:
                initIntent("个人信息",PersonalInformationyActivity.class);
                break;
            case R.id.drawer_item2:
                initIntent("我的收藏",FeedBackActivity.class);
                break;
            case R.id.drawer_item3:
                initIntent("功能介绍",FunctionIntrodutionActivity.class);
                break;
            case R.id.drawer_item4:
                initIntent("帮助",FeedBackActivity.class);
                break;
            case R.id.drawer_item5:
                initIntent("反馈",FeedBackActivity.class);
                break;
            case R.id.drawer_item6:
                initIntent("设置",FeedBackActivity.class);
                break;
            case R.id.drawer_item7:
                if (color!=-1) {
                    binding.fragmentDrawer.setBackgroundColor(getResources().getColor(R.color.colorYellow));
                    color=-1;
                }else{
                    binding.fragmentDrawer.setBackgroundColor(getResources().getColor(R.color.colorPrimary));
                    color=-2;
                }

                break;
        }
    }

    private void initIntent(String logn,Class aClass) {
        Intent intent = new Intent(getContext(), aClass);
        intent.putExtra("logn", logn);
        startActivity(intent);
    }

}
